<?php
class NX_MysqlPdo{
	protected static $_instance = array();
	public $_log = null;
	public $_db;

	// 构造函数
	public function __construct(){
	}

	// 析构函数
	public function __destruct(){

	}

	// 得到对象
	public static function getInstance($cfg){
		$key = serialize($cfg);
		// 生成缓存
		if(!isset(self::$_instance[$key]) || !self::$_instance[$key] instanceof self){
			self::$_instance[$key] = new self();
			self::$_instance[$key]->_log = NX_Log::getLog(__CLASS__);
			self::$_instance[$key]->connDb($cfg);
		}
		// 返回缓存
		return self::$_instance[$key];
	}

	// 连接数据库
	private function connDb($cfg){
		if(!isset($cfg['port'])){
			$cfg['port'] = 3306;
		}
		try{
			$dsn = 'mysql:host='.$cfg['host'].';port='.$cfg['port'].';dbname='.$cfg['db'];
			$this->_db = new PDO($dsn,$cfg['user'], $cfg['password']);
			if(isset($cfg['charset'])){
				$this->_db->exec('set names '.$cfg['charset']);
			}
		}catch (Exception $e) {
			$this->_log->error('Conn Mysql '.$cfg['host'].' '.$cfg['db'].' Err!');
		}
	}
	
	// 取单行纪录
	public function getOne(){
		
	}
	
	// 取多行纪录
	public function getArr(){
		
	}
	
	// Insert 纪录
	public function insert($tbl,$sql){
		
	}
	
	
	public function select($tbl,$data,$where){
		
	}
	
	public function update($tbl,$sql){
		
	}
	
}
?>